<html>
 <head>
  <title>Daftar Proyek</title>
  <link href="../../css/lov.css" rel="stylesheet" type="text/css" />

  <script language="javascript" type="text/javascript">
   function selectProyek(id_proyek,nama_proyek){
	   window.parent.selectProyek(id_proyek,nama_proyek);
	   window.parent.tb_remove();
   }


  </script>
 </head>
<body class="bodyLOV">

<?php
include '../../modul/general.php';
//Paging
$table = "m_proyek";
$SQL = "SELECT id_proyek,nama_proyek FROM $table";

$dataperhal = 10;
    if(isset($_GET['page'])){
        $noPage= $_GET['page'];}
    else{
        $noPage= 1;
    }
$start = ($noPage-1)*$dataperhal;

$search = $_POST['search_name'];

// field seacrh
$sqlq = getRSq($SQL);
$jmlField = pg_num_fields($sqlq);
for ($x=0;$x<$jmlField;$x++){
    $namaField = pg_field_name($sqlq, $x);
    $cond .= "CAST(lower(".$namaField.") as TEXT) LIKE lower('%$search%') OR ";
}
$condition = substr($cond,0,strlen($cond)-3);
// end field search
if(isset($_POST['search'])){
    $noPage= 1;
	 $SQL .= " WHERE $condition";
         $SQL .= " ORDER BY id_proyek ASC";
         if ($search==""){
         $SQL .= " OFFSET $start LIMIT $dataperhal ";
         }
 }else{
         $SQL .= " ORDER BY id_proyek ASC";
         $SQL .= " OFFSET $start LIMIT $dataperhal ";
 }
 $query = getRS($SQL);

?>
<div class="big-border">
<div class="big-border-search">
<form action="" method="post">
 <div class="border-search">
 <input class="inputLOV" id="search_name" type="text" name="search_name" size="20" value="<?php echo $search; ?>" />
 <button type="submit" class="searchLOV" name="search">Search</button>
 </div>
 <!--<input class="search" type="submit" name="search" value="" />-->
</form>
</div>
    <div class="big-border-inside">
    <table class="tableLOV" bgcolor="#000000" cellspacing="1" cellpadding="3">

            <?php
            if ($query==""){
                echo "<div class='norecord'>No Record</div>";
            }else{
                echo "<tr bgcolor='#DDDDDD'>
                        <th>Id Proyek</th>
                        <th>Name Proyek</th>

                </tr>";
            $query = getRSq($SQL);
            while($row = pg_fetch_object($query)): ?>
            <tr bgcolor="#FFFFFF">
                    <td align="center"><a href="javascript:selectProyek('<?=trim($row->id_proyek)?>','<?=trim($row->nama_proyek)?>')"><?=$row->id_proyek?></a></td>
                    <td><?=trim($row->nama_proyek)?></td>
            </tr>
            <?php endwhile;
            }
            ?>

    </table>
    </div>

<div class="border-nopaging">
    <?php
    $query2 = "SELECT * From $table";
    $data2 = getRSq($query2);
    $jumData = pg_num_rows($data2);
    $jumPage = ceil($jumData/$dataperhal);
    $showPage = 0;
    if ($noPage > 1) echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage-1)."'>Prev</a>";
    for($page = 1; $page <= $jumPage; $page++)
        {
                 if ((($page >= $noPage-2) && ($page <= $noPage + 2)) || ($page == 1) || ($page == $jumPage))
                {
                    if (($showPage == 1) && ($page != 2))  echo "...";
                    if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
                    if ($page == $noPage) echo " <b>".$page."</b> ";
                    else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a> ";
                    $showPage = $page;
                 }
        }
    if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage+1)."'>Next</a>";
    ?>
</div>
</div>
</body>
</html>
